package com.example.consumer.listener;

import com.alibaba.fastjson.JSON;
import com.example.common.entity.MsgTest;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Slf4j
@Component
public class PolymerizationConsumer {
    /**
     * 同服中不能出现topic和consumerGroup相同的消费者，即使监听的消息体不同（MsgTest或者其他的）
     */
    @Service
    @RocketMQMessageListener(topic = "first-topic-pojo", selectorExpression = "*", consumerGroup = "polymerization_consumer")
    //consumeMode = ConsumeMode.ORDERLY,指定消费模式为顺序消费
    // reconsumeTimes = -1   重试次数 reconsumeTimes = -1 代表一直重试  重试次数 reconsumeTimes = 3
    //顺序消息消费失败，默认不重试(官方是一直重试)
    //指定连接某个MQ集群@RocketMQMessageListener(nameServer = "127.0.0.1:9877", instanceName = "tradeCluster", topic = "test-topic-3", consumerGroup = "my-consumer_test-topic-3")
    public class ConsumerSend implements RocketMQListener<MsgTest> {
        // 监听到消息就会执行此方法
        @Override
        public void onMessage(MsgTest msg) {
            log.info("监听到消息：msg={}", JSON.toJSONString(msg));
        }
    }





}
